<?php

ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once '../../../sql/connection.php';

$addStuID = $_POST['addStuID'];
$classID = $_POST['classID'];
$addStuName = $_POST['addStuName'];
$addStuPwd = password_hash("123456", PASSWORD_DEFAULT);

// 查询语句
$querySql = "select id, create_time, update_time, stu_ID, stu_name, stu_pwd, is_delete from student_info where stu_ID='$addStuID'";
// 连接数据库，并查询
$result = mysqli_query($GLOBALS['conn'], $querySql);

//echo $result_config;
if (mysqli_num_rows($result) > 0) {
	echo "
<script>
    alert('该学号已存在，请重新输入！');
    history.go(-1);
</script>";
} else {
	$now = date('Y-m-d H:i:s', time());
	$addSql = "INSERT INTO student_info(create_time, update_time, stu_ID, stu_name, stu_pwd, class_ID, is_delete)VALUES ('$now','$now','$addStuID','$addStuName','$addStuPwd', '$classID' ,0)";
	if (mysqli_query($GLOBALS['conn'], $addSql)) {
		echo "
            <script>
                alert('添加成功！');
                window.location.href=document.referrer;
            </script>
        ";
	} else {
		echo "
            <script>
                alert('添加失败！');
                history.back();
            </script>
        ";
	}
	
}

